Description
Spectrum UI Icons delivered in a flexible template tag so that they can be leveraged across various frameworks. The default export of this package pre-applies the html
template tag from lit-html
for ease of use in the Spectrum Web Components library. Please remember to consult Spectrum's Iconography Guidelines when planning how to leverage these icons in the visual delivery of your application. For technical information on using these iconos in projects powered by various javascript frameworks, check out the "Extended use cases" sectino below.
Usage
![How big is this package in your project?](https://img.shields.io/bundlephobia/minzip/@spectrum-web-components/icons-ui?style=for-the-badge)
yarn add @spectrum-web-components/icons-ui
With the default exports of the packages prepared with the html
template tag from lit-html
, the default value of an icon export will be as follows:
import { LitElement, html } from 'lit-element';
import '@spectrum-web-components/icon';
import { AsteriskIcon } from '@spectrum-web-components/icons-ui';
class ElementWithIcon extends LitElement {
protected render(): TemplateResult {
return html`
<sp-icon>
${AsteriskIcon()}
</sp-icon>
`
}
}
customElements.define('element-with-icon', ElementWithIcon);
Every icons can be customized via the following options:
{
width: 24,
height: 24,
hidden: false,
title: 'Icon title',
}
Extended use cases
The default exports of this package are pre-wrapped via setCustomTemplateLiteralTag
in the html
template tag from lit-html
, and work liek the following::
import { AsteriskIcon } from '@spectrum-web-components/icons-ui';
console.log(AsteriskIcon());
When working in the context of other frameworks, it is possible to import the icons with a generic template tag as follows:
import { AsteriskIcon } from '@spectrum-web-components/icons-ui/src/icons.js';
console.log(AsteriskIcon());
What's more, if you're already working with a specific parser in your project, you can assign it as the one to use when delivering the icons in order to be sure that the SVG content is delivered as parsed content to your final template. The means if you were working with Preact via the htm
tag as bound to the provided hyperscript function:
import {
AsteriskIcon,
setCustomTemplateLiteralTag,
} from '@spectrum-web-components/icons-ui/src/icons.js';
import htm from 'htm';
import { h } from 'preact';
const hPreact = htm.bind(h);
setCustomTemplateLiteralTag(hPreact);
console.log(AsteriskIcon());
In this way the icons exported by @spectrum-web-components/icons-ui
can be leveraged in projects powered by the the likes of hyperHTML, lighterhtml, lit-html, Preact, React, Vanilla JS, Vue.js, and more!